package com.accelstack.cmp.repository;

import com.accelstack.cmp.entity.VirtualizationHost;
import com.accelstack.cmp.enums.HostStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 虚拟化主机Repository
 */
@Repository
public interface VirtualizationHostRepository extends JpaRepository<VirtualizationHost, Long> {
    
    /**
     * 根据服务器ID查询虚拟化主机
     */
    VirtualizationHost findByServerId(Long serverId);
    
    /**
     * 根据状态查询虚拟化主机列表
     */
    List<VirtualizationHost> findByStatus(HostStatus status);
    
    /**
     * 查询虚拟化主机（包含服务器和平台信息）
     */
    @Query("SELECT vh FROM VirtualizationHost vh LEFT JOIN FETCH vh.server LEFT JOIN FETCH vh.virtPlatform WHERE vh.id = :id")
    VirtualizationHost findByIdWithRelations(@Param("id") Long id);
}

